<template>
	<view class="w-100">
		<view class="flex-1 head-bg"></view>
		<view class="flex-1 mx-3 user-info-box">
			<view class="flex-1 d-f">
				<view class="flex-1 row-ac">
					<view class="head-img ml-3 mt-3">
						<image :src="userInfo.head_image" mode=""></image>
					</view>
					<view class="ml-3">
						<view class="font-s-6 font-w in1line">{{ userInfo.nickname || userInfo.username }} ~ 志愿者</view>
						<view class="row-ac mt-1">
							<view class="user-level-box row font-s-3 font-w">LV</view>
							<view class="user-level-name row font-s-3 font-w"><text class="ml-2">志愿者</text></view>
						</view>
					</view>
				</view>
				<view class="iconfont icon-name-card mt-3 mr-3" @click="toDistributorsInfo"></view>
			</view>

			<view class="flex-1 mt-4">
				<view class="flex-1 py-2 mx-3 font-s-5 font-w">我的收益</view>
				<view class="row-ac flex-1">
					<view class="flex-1 row-a-j-fc">
						<view class="font-s-6 font-w">{{ userCommission.used_commission }}</view>
						<view class="font-s-2 text-muted mt-1">已提现金额</view>
					</view>
					<view class="flex-1 row-a-j-fc">
						<view class="font-s-6 font-w">{{ userCommission.added_commission }}</view>
						<view class="font-s-2 text-muted mt-1">可提现金额</view>
					</view>
					<view class="flex-1 row-a-j-fc">
						<view class="font-s-6 font-w">{{ userCommission.total_commission }}</view>
						<view class="font-s-2 text-muted mt-1">总收益</view>
					</view>
				</view>
			</view>
			<view class="flex-1 mt-4 pb-5">
				<view class="flex-1 py-2 mx-3 font-s-5 font-w">我的团队</view>
				<view class="row-ac flex-1">
					<view class="flex-1 row-a-j-fc">
						<view class="font-s-6 font-w">{{ distriDetail.leader_name || '无' }}</view>
						<view class="font-s-2 text-muted mt-1">我的上级</view>
					</view>
					<view class="flex-1 row-a-j-fc">
						<view class="font-s-6 font-w">{{ distriSubTotal }}</view>
						<view class="font-s-2 text-muted mt-1">我的下级</view>
					</view>
				</view>
			</view>
		</view>
		<view class="flex-1 mx-3 mt-3">
			<view class="py-4 row-ac-sb border-bottom flex-1" v-for="(item,index) in tabList" :key="index"
				@click="navTo(item)">
				<view class="font-s-5 font-w-400 row-ac">
					<view class="iconfont tab-icon" :class="item.icon"></view>
					<view class="ml-1">{{ item.name }}</view>
				</view>
				<view class="text-muted iconfont icon-next-01" style="font-size: 20rpx;"></view>
			</view>
			<view class="py-4 row-ac-sb border-bottom flex-1"
				@click="navToSet">
				<view class="font-s-5 font-w-400 row-ac">
					<view class="iconfont tab-icon icon-shezhi2"></view>
					<view class="ml-1">志原者设置</view>
				</view>
				<view class="text-muted iconfont icon-next-01" style="font-size: 20rpx;"></view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		userInfoUrl,
	} from '@/api/index.js';
	import {
		distributorsDetailUrl,
		commissionstatsUrl,
		distributorsSubUrl
	} from '@/api/promotion';
	export default {
		data() {
			return {
				userInfo: '',
				userCommission: '',
				distriDetail: '',
				distriSubList: [],
				distriSubTotal: '',
				tabList: [{
						id: 0,
						name: '我的下级',
						icon: 'icon-yonghuhaoyou',
						url: '/pages/shop/promotion/distribution/distribution-team'
					},
					{
						id: 1,
						name: '收益报表',
						icon: 'icon-tuiguangzhuanqian',
						url: '/pages/shop/promotion/distribution/distribution-report'
					},
					{
						id: 2,
						name: '我要提现',
						icon: 'icon-qianbao',
						url: '/pages/shop/promotion/distribution/distribution-withdrawal'
					}
				]
			}
		},
		onLoad() {

		},
		mounted() {
			this.token = uni.getStorageSync('token')
			if (this.token != '') {
				this.loginStatus = true
				this.getUserInfo()
			} else {
				this.loginStatus = false
			}
		},
		methods: {
			getUserInfo() {
				this.$R.get(userInfoUrl).then(res => {
					this.userInfo = res.data
					this.getCommissionstats(this.userInfo.id)
					this.getDistributorsDetail(this.userInfo.id)
					this.getDistributorsSub(this.userInfo.id)
				})
			},
			getCommissionstats(userId) {
				this.$R.get(commissionstatsUrl + userId + '/').then(res => {
					this.userCommission = res.data
				})
			},
			getDistributorsDetail(userId) {
				this.$R.get(distributorsDetailUrl + userId + '/').then(res => {
					this.distriDetail = res.data
				})
			},
			getDistributorsSub(userId) {
				this.$R.get(distributorsSubUrl + userId + '/').then(res => {
					this.distriSubList = res.data.list
					this.distriSubTotal = res.data.total
				})
			},
			navTo(item) {
				uni.navigateTo({
					url: item.url
				});
			},
			toDistributorsInfo() {
				uni.navigateTo({
					url: '/pages/shop/promotion/distribution/distributors-info'
				});
			},
			navToSet(){
				uni.navigateTo({
					url: '/pages/shop/promotion/distribution/distribution-set?userId=' + this.userInfo.id
				});
			}
		}
	}
</script>

<style lang="scss">
	.head-bg {
		height: 300rpx;
		background-color: #FF6F07;
		border-radius: 0 0 80rpx 80rpx;
	}

	.user-info-box {
		box-shadow: 6rpx 2rpx 20rpx #CDCDCD;
		background-color: #fff;
		border-radius: 20rpx;
		position: relative;
		margin-top: -280rpx;
		z-index: 90;

		.head-img {
			width: 160rpx;
			height: 160rpx;
			border-radius: 50%;

			image {
				width: 160rpx;
				height: 160rpx;
				border-radius: 50%;
			}
		}

		.user-level-box {
			width: 42rpx;
			height: 42rpx;
			border-radius: 50%;
			background-color: #FF6F07;
			color: #fff;
			border: 2rpx solid #fff;
			z-index: 9;
		}

		.user-level-name {
			height: 42rpx;
			line-height: 42rpx;
			padding: 0 22rpx;
			background-color: #FF6F07;
			color: #fff;
			margin-left: -30rpx;
			border-radius: 10rpx;
		}

		.icon-name-card {
			font-size: 52rpx;
			color: #FF6F07;
		}
	}

	.tab-icon {
		color: #FF6F07;
		font-size: 36rpx;
	}
</style>